package com.erp.util;

import org.jeecgframework.core.common.dao.jdbc.JdbcDao;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.web.system.sms.service.TSSmsTemplateSqlServiceI;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 
  * @ClassName: TuiSongMsgUtil 统一发送消息的公用方法
  * @Description: TODO
  * @author Comsys-skyCc cmzcheng@gmail.com
  * @date 2014-9-18 下午3:20:34
  *
 */
public class erpUtil {

//17	销售订单	t_sd_so_head
//259	生产入库	t_mm_prdgr_head
//15	销售交货	t_mm_sogi_head
//16	销售退货	t_mm_sore_head
//260	生产发料	t_mm_prdgi_head
//261	生产退料	t_mm_prdre_head
//21	采购退货	t_mm_po_re_head
//20	采购收货	t_mm_po_gr_head
//22	采购订单	t_mm_po_head
//60	物料消耗	t_mm_scrap_head
//202	生产订单	t_pp_order


    public  static  String getdocnum(String objtype){
        JdbcDao jdbcDao = ApplicationContextUtil.getContext().getBean(JdbcDao.class);
        Statement stmt = null;
        ResultSet rs = null;
        Connection conn = null;
        String docnum=null;
        try {
            conn = jdbcDao.getDataSource().getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        CallableStatement proc = null;
        Date d=new Date();//获取时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//转换格式

        try{
        proc = conn.prepareCall("{ call p_createdocnum(?,?,?) }");
        proc.setString(1, objtype);
        proc.setString(2, sdf.format(d));
        proc.registerOutParameter(3, Types.VARCHAR);
        proc.execute();
        docnum = proc.getString(3);
        }catch (Exception e){

        }
        return  docnum;
    }

	public static Map<String,String> saveentity(String objtype,String transtype,String doc){
		JdbcDao jdbcDao = ApplicationContextUtil.getContext().getBean(JdbcDao.class);
		Statement stmt = null;
		ResultSet rs = null;
		Connection conn = null;
        Map<String,String> resultmap = new HashMap<String, String>() ;
        try {
            conn = jdbcDao.getDataSource().getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        CallableStatement proc = null;

        try{
            proc = conn.prepareCall("{ call p_savestock(?,?,?,?,?) }");
            proc.setString(1, objtype);
            proc.setString(2, transtype );
            proc.setString(3, doc );
            proc.registerOutParameter(4, Types.VARCHAR);
            proc.registerOutParameter(5, Types.VARCHAR);
            proc.execute();
            resultmap.put("code",proc.getString(4));
            resultmap.put("message",proc.getString(5));
        }catch (Exception e){

        }
        return  resultmap;
	}
	public static TSSmsTemplateSqlServiceI getTssmsTemplateSqlInstance(){
		
		TSSmsTemplateSqlServiceI tSSmsTemplateSqlService = ApplicationContextUtil.getContext().getBean(TSSmsTemplateSqlServiceI.class);
			
		return tSSmsTemplateSqlService;
	}


}
